import 'dart:io';

import 'package:BeeApp/CarPage/MainCarUserPage.dart';
import 'package:BeeApp/LoginAndRegister/ChooseUserPage.dart';
import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:BeeApp/ShopPage/MainUserPage.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluwx/fluwx.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter/cupertino.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await AmapLocation.instance.init(iosKey: 'e5b94ea20faba1746723d30ad211574d');
  await registerWxApi(
      appId: "wxdeefc62797ce4092",
      doOnAndroid: true,
      doOnIOS: true,
      universalLink: "https://fengxing.581vv.com");
  var result = await isWeChatInstalled;
  print("is installed $result");
  SpUtil.getInstance().then((value) {
    print("登录类型 " + getData("loginType").toString());
    print("用户类型 " + getData("AppType").toString());
    if (getData("loginType") == "1") {
      if (getData("AppType") == "1") {
        runApp(UserApp());
      } else {
        runApp(CarApp());
      }
    } else {
      runApp(MyApp());
    }
  });
  if (Platform.isAndroid) {
    // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
    SystemUiOverlayStyle systemUiOverlayStyle =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    setDesignWHD(750, 1334, density: 2.0);
    WidgetsFlutterBinding.ensureInitialized();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
    return MaterialApp(
        localizationsDelegates: [
          RefreshLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          DefaultCupertinoLocalizations.delegate,
        ],
        supportedLocales: [
          const Locale('zh'),
          const Locale('en'),
        ],
        theme: ThemeData(primaryColor: Colors.white),
        title: 'Flutter Demo',
        // home: MainUserPage(),
        home: ChooseUserPage()
        // home: MainCarUserPage(),
        );
  }
}

class UserApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    setDesignWHD(750, 1334, density: 2.0);
    WidgetsFlutterBinding.ensureInitialized();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
    return MaterialApp(
      localizationsDelegates: [
        RefreshLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        DefaultCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('zh'),
        const Locale('en'),
      ],
      theme: ThemeData(primaryColor: Colors.white),
      title: 'Flutter Demo',
      home: MainUserPage(),
      // home: MainCarUserPage(),
    );
  }
}

class CarApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    setDesignWHD(750, 1334, density: 2.0);
    WidgetsFlutterBinding.ensureInitialized();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
    return MaterialApp(
      localizationsDelegates: [
        RefreshLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        DefaultCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('zh'),
        const Locale('en'),
      ],
      theme: ThemeData(primaryColor: Colors.white),
      title: 'Flutter Demo',
      // home: MainUserPage(),
      home: MainCarUserPage(),
    );
  }
}
